<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改设备')" />
    <th:block th:include="include :: ztree-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-device-edit" th:object="${device}">
        <input id="deviceId" name="deviceId" type="hidden" th:field="*{deviceId}"/>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">设备名称：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="deviceName" id="deviceName" th:field="*{deviceName}" disabled required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">设备编号：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="deviceCode" id="deviceCode" th:field="*{deviceCode}" disabled required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">价格：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="price" id="price" th:field="*{price}" disabled required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">手机号：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="phone" id="phone" th:field="*{phone}" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">地址：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="address" id="address" th:field="*{address}" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">备注：</label>
            <div class="col-sm-8">
                <input id="remark" name="remark" class="form-control" type="text" th:field="*{remark}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">支付方式：</label>
            <div class="col-sm-8">
                <select name="payMethod" class="form-control m-b">
                    <option value="wx" selected>微信</option>
                    <option value="ali">支付宝</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label"></label>
            <div class="col-sm-8">
                <button class="btn" type="button" onclick="edit()">支付</button>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label"></label>
            <div class="col-sm-8">
                <div id="wxcode"></div>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<script src="https://cdn.bootcss.com/jquery.qrcode/1.0/jquery.qrcode.min.js"></script>
<script type="text/javascript">

    function edit() {
        var deviceId = $("input[name='deviceId']").val();
        var phone = $("input[name='phone']").val();
        var address = $("input[name='address']").val();
        var remark = $("input[name='remark']").val();
        var payMethod = $("select[name='payMethod']").val();
        $.ajax({
            cache : true,
            type : "POST",
            url : ctx + "system/device/pay",
            data : {
                "deviceId": deviceId,
                "phone": phone,
                "address": address,
                "remark": remark,
                "payMethod": payMethod
            },
            async : false,
            error : function(request) {
                $.modal.alertError("系统错误");
            },
            success : function(data) {
                if(payMethod == "ali") {
                    var parent = activeWindow();
                    parent.$("#result").html(data.data);
                    // $.modal.confirm("确认支付成功?", function () {
                    //     $.operate.successCallback(data);
                    // });
                }
                if(payMethod == "wx"){
                    $('#wxcode').empty();
                    $('#wxcode').qrcode(data.data.codeUrl)
                }
            }
        });
    }

    function submitHandler() {
        // if ($.validate.form()) {
        //     edit();
        // }
        $.modal.confirm("确认支付成功?", function () {
            var result = {"code":"0","msg":"操作成功"};
            $.operate.successCallback(result);
        });
    }
</script>
</body>
</html>
